//****************************************************************
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   CatalogSFIFindQuery.java  $$
//* $$Revision:   1.0  $$
//* $$Author:   aponte  $$
//* $$Date:   Dec 10 2008 11:00:04  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas003ColorVw;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas101CatalogVw;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class CatalogSFIFindQuery implements CustomExpressionFactory {

	public Expression createExpression(ExpressionBuilder builder,
			Object[] parameters) {

		Timestamp fechaInicio = (Timestamp) parameters[0];
		Timestamp fechaFin = (Timestamp) parameters[1];
		Ncas101CatalogVw ncas101CatalogVw = (Ncas101CatalogVw) parameters[2];
		Ncas003ColorVw ncas003ColorVw = (Ncas003ColorVw) parameters[3];

		Expression exp = null;

		exp = builder.get("ncas101CatalogVw").equal(ncas101CatalogVw);

		exp = exp.and(builder.get("ncas104SfiVw").get("cas104SfiInDateY")
				.lessThan(fechaInicio)); // equal??

		exp = exp.and(builder.get("ncas104SfiVw").get("cas104SfiOutDateY")
				.greaterThan(fechaFin));

		//agrego que el color sea null o sea el que se selecciono
		if (ncas003ColorVw != null){
			exp = exp.and(builder.get("ncas104SfiVw").get("cas104ColorCodeC")
					.isNull().or(
							builder.get("ncas104SfiVw").get("cas104ColorCodeC")
									.equal(ncas003ColorVw)));
		}

		return exp;
	}

}
